package com.wxf.dao.impl;

import com.wxf.bean.DBUtils;
import com.wxf.bean.Users;
import com.wxf.dao.UsersDao;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;

public class UsersDaoImpl extends DBUtils implements UsersDao {
    @Override
    public Users login(String userName, String password){

        String sql = "select * from users where loginName = ? and password = ?";
        ArrayList paramList = new ArrayList();
        paramList.add(userName);
        paramList.add(password);
        resultSet = query(sql,paramList);
        Users user = null;
        try {
            if(resultSet==null){
                return null;
            }
            while (resultSet.next()) {
                user = new Users();
                user.setUserName(userName);
                user.setUserId(resultSet.getInt("userid"));
                user.setRealName(resultSet.getString("realName"));
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            closeAll();
        }
        return user;
    }
}
